#include "frmlogin.h"
#include "ui_frmlogin.h"
#include "frmfindpassword.h"

frmLogin::frmLogin(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::frmLogin)
{
    ui->setupUi(this);
    QImage image1;
    image1.load(":/img/backgroud.jpg");
    QImage image2=image1.scaled(1000,450);

    QPalette palette;
    palette.setBrush(this->backgroundRole(),QBrush(image2));//设置背景
    setPalette(palette);
}

frmLogin::~frmLogin()
{
    delete ui;
}

void frmLogin::on_btnLogin_clicked()
{
    //获取用户输入的内容
    string name = ui->letName->text().toStdString();
    string password = ui->letPassword->text().toStdString();
    //验证密码和用户名
    for(int i = 0; i < UserList::userlist->size(); i++){
        User *u = UserList::userlist->at(i);
        if(name == u->name){
            if(password == u->password){
                this->id = i;
                this->close();
                accept();//main.cpp
                return ;
            }
        }
    }
    QMessageBox::critical(this, "错误", "用户名或密码错误！");
}
//注册
void frmLogin::on_clbLogon_clicked()
{
    frmLogon *flo = new frmLogon();
    flo->setWindowModality(Qt::ApplicationModal);
    flo->show();
}

//忘记密码
void frmLogin::on_clbFindPassword_clicked()
{
    frmFindPassword *ffp = new frmFindPassword;
    ffp->setWindowModality(Qt::ApplicationModal);
    ffp->show();
}

int frmLogin::getId()
{
    return id;
}
